package springboot.service.impl;

import java.util.concurrent.atomic.AtomicLong;
import javax.annotation.Resource;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import springboot.entity.Teacher;
import springboot.repository.TeacherRepository;
import springboot.service.TeacherService;

@Service
public class TeacherServiceImpl implements TeacherService {

  @Resource
  private TeacherRepository teacherRepository;
  private static final AtomicLong ID = new AtomicLong(System.currentTimeMillis());


  @Override
  public Teacher queryById(Long tno) {
    return teacherRepository.queryById(tno);
  }

  @Transactional
  @Override
  public Long createTeacher(Teacher teacher) {
    teacher.setTno(ID.getAndIncrement());
    this.teacherRepository.create(teacher);
    return teacher.getTno();
  }
}
